ListViewItem ItemSelectionChangedEvent 觸發 4 次 [e.Selected 觸發兩次] 導致 Win32 異常未處理 (ListViewItem ItemSelectionChangedEvent Fires 4 times [e.Selected fires twice] leads to Win32 Exception Unhandled)


問題描述

ListViewItem ItemSelectionChangedEvent 觸發 4 次 [e.Selected 觸發兩次] 導致 Win32 異常未處理 (ListViewItem ItemSelectionChangedEvent Fires 4 times [e.Selected fires twice] leads to Win32 Exception Unhandled)

I am using a button and a listview to display a list of options to the user. Selection is made with a mouse click, the listview removes its self from the .Controls array + un‑registers eventlistener and loads a new listview else where on the screen.

My problem is both listviews trigger e.selected twice:

' private void _lvKids_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
    {
        if (e.IsSelected)//fires twice per click
        {
            HideKidsList();//‑‑REMOVE CURRENT LISTVIEW
            ValidateUser();//CREATE NEW LISTVIEW
        }`

If the button is clicked a second time to restart the process, it causes a win32 Exception. After much research, this exception is the often the cause of a memory leak. So I'm thinking memory leak?

When I first started, listboxes were used which worked perfectly. I'd love to able to use them, but my form has a graphic for a background and listbox doesn't. Listview does.

I don't have anyone to turn to so any thing you can offer would be appreciated.

Thanks; Sam

‑‑‑‑‑

參考解法

方法 1:

An update if anyone else has the same issue. Selecting the listview item called for it to be removed from Controls array. Removing the listview also cause the selected item to be deselected, thus 4 calls to the handler.

(by OverMarsOverMars)

參考文件

  1. ListViewItem ItemSelectionChangedEvent Fires 4 times [e.Selected fires twice] leads to Win32 Exception Unhandled (CC BY‑SA 3.0/4.0)

#listview #memory #events #click






相關問題

ListView中的序列號列 (Serial number Column in ListView)

狀態列表可繪製在預蜂窩版本上無法正常工作 (State list drawable not working properly on pre-honeycomb versions)

我可以減少列表視圖的執行時間嗎? (Can i reduce execution time of listview?)

ListView Windows 8 多個索引 (ListView Windows 8 multiple indexes)

如何通過單擊歌曲列表來播放歌曲 (How to play the song by clicking the lists of song)

Thuộc tính chi tiết trong ListView không hiển thị (Details property in ListView not displaying)

如何從 DataModel 動態訪問數據以獲取 Blackberry 10 中的可折疊列表 (How to access data dynamically from DataModel for collapsible list in Blackberry 10)

android如何將listview項目發送到另一個活動 (android How to send listview item to another activity)

實現 RecyclerView (Implementing RecyclerView)

如何刪除列表視圖底部的多餘空間? (How can I remove extraspace in listview bottom?)

ListViewItem ItemSelectionChangedEvent 觸發 4 次 [e.Selected 觸發兩次] 導致 Win32 異常未處理 (ListViewItem ItemSelectionChangedEvent Fires 4 times [e.Selected fires twice] leads to Win32 Exception Unhandled)

Kivy:如何使用 RecycleView 在 Kivy 中顯示具有可變行的列表? (Kivy: how to display a list with variable rows in Kivy with a RecycleView?)







留言討論